g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL);
- /* Create the list widget here.
- */
- list = gtk_list_view_new_with_factory (factory);
- /* We connect the activate signal here. It's the function we defined
- * above for launching the selected application.
- */
- g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL);
-
/* And of course we need to set the data model. Here we call the function
* we wrote above that gives us the list of applications. Then we set
* it on the list widget.
* to create as many listitems as it needs to show itself to the user.
*/
model = create_application_list ();
- gtk_list_view_set_model (GTK_LIST_VIEW (list), model);
- g_object_unref (model);
+
+ /* Create the list widget here.
+ */
+ list = gtk_list_view_new_with_factory (model, factory);
+
+ /* We connect the activate signal here. It's the function we defined
+ * above for launching the selected application.
+ */
+ g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL);
/* List widgets should always be contained in a #GtkScrolledWindow,
* because otherwise they might get too large or they might not
create_weather_view (void)
{
GtkWidget *listview;
- GListModel *selection;
+ GListModel *model;
GtkListItemFactory *factory;
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_widget), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_widget), NULL);
- listview = gtk_list_view_new_with_factory (factory);
+ model = G_LIST_MODEL (gtk_no_selection_new (create_weather_model ()));
+ listview = gtk_list_view_new_with_factory (model, factory);
gtk_orientable_set_orientation (GTK_ORIENTABLE (listview), GTK_ORIENTATION_HORIZONTAL);
gtk_list_view_set_show_separators (GTK_LIST_VIEW (listview), TRUE);
- selection = G_LIST_MODEL (gtk_no_selection_new (create_weather_model ()));
- gtk_list_view_set_model (GTK_LIST_VIEW (listview), selection);
- g_object_unref (selection);
return listview;
}
{
GtkWidget *header, *listview, *sw, *vbox, *search_entry, *open_button, *overlay;
GtkFilterListModel *filter_model;
- GtkNoSelection *selection;
GtkStringList *stringlist;
GtkFilter *filter;
GFile *file;
gtk_overlay_set_child (GTK_OVERLAY (overlay), sw);
listview = gtk_list_view_new_with_factory (
+ G_LIST_MODEL (gtk_no_selection_new (G_LIST_MODEL (filter_model))),
gtk_builder_list_item_factory_new_from_bytes (NULL,
g_bytes_new_static (factory_text, strlen (factory_text))));
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
- selection = gtk_no_selection_new (G_LIST_MODEL (filter_model));
- gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selection));
- g_object_unref (selection);
g_signal_connect (filter_model, "items-changed", G_CALLBACK (update_title_cb), progress);
g_signal_connect (filter_model, "notify::pending", G_CALLBACK (update_title_cb), progress);
self->sorter = gtk_column_view_sorter_new ();
self->factory = gtk_column_list_item_factory_new (self);
- self->listview = GTK_LIST_VIEW (gtk_list_view_new_with_factory (
+ self->listview = GTK_LIST_VIEW (gtk_list_view_new_with_factory (NULL,
GTK_LIST_ITEM_FACTORY (g_object_ref (self->factory))));
gtk_widget_set_hexpand (GTK_WIDGET (self->listview), TRUE);
gtk_widget_set_vexpand (GTK_WIDGET (self->listview), TRUE);
gtk_box_append (GTK_BOX (vbox), scrolled);
gtk_widget_show (scrolled);
- listview = gtk_list_view_new ();
- gtk_widget_set_size_request (listview, 140, -1);
-
model = G_LIST_MODEL (gtk_single_selection_new (g_object_ref (G_LIST_MODEL (dialog->custom_paper_list))));
- gtk_list_view_set_model (GTK_LIST_VIEW (listview), model);
g_signal_connect (model, "notify::selected", G_CALLBACK (selected_custom_paper_changed), dialog);
- g_object_unref (model);
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_item), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_item), NULL);
g_signal_connect (factory, "unbind", G_CALLBACK (unbind_item), NULL);
- gtk_list_view_set_factory (GTK_LIST_VIEW (listview), factory);
- g_object_unref (factory);
+
+ listview = gtk_list_view_new_with_factory (model, factory);
+ gtk_widget_set_size_request (listview, 140, -1);
dialog->listview = listview;
*
* ...
*
+ * model = create_application_list ();
+ *
* factory = gtk_signal_list_item_factory_new ();
* g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
* g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL);
*
- * list = gtk_list_view_new_with_factory (factory);
+ * list = gtk_list_view_new_with_factory (model, factory);
*
* g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL);
*
- * model = create_application_list ();
- * gtk_list_view_set_model (GTK_LIST_VIEW (list), model);
- * g_object_unref (model);
- *
* gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
* ]|
*
/**
* gtk_list_view_new:
+ * @model: (allow-none) (transfer full): the model to use, or %NULL
*
- * Creates a new empty #GtkListView.
+ * Creates a new #GtkListView.
*
- * You most likely want to call gtk_list_view_set_factory() to
- * set up a way to map its items to widgets and gtk_list_view_set_model()
- * to set a model to provide items next.
+ * You most likely want to call gtk_list_view_set_factory()
+ * to set up a way to map its items to widgets.
*
* Returns: a new #GtkListView
**/
GtkWidget *
-gtk_list_view_new (void)
+gtk_list_view_new (GListModel *model)
{
- return g_object_new (GTK_TYPE_LIST_VIEW, NULL);
+ GtkWidget *result;
+
+ g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
+
+ result = g_object_new (GTK_TYPE_LIST_VIEW,
+ "model", model,
+ NULL);
+
+ /* consume the reference */
+ g_clear_object (&model);
+
+ return result;
}
/**
* gtk_list_view_new_with_factory:
- * @factory: (transfer full): The factory to populate items with
+ * @model: (allow-none) (transfer full): the model to use, or %NULL
+ * @factory: (allow-none) (transfer full): The factory to populate items with, or %NULL
*
* Creates a new #GtkListView that uses the given @factory for
* mapping items to widgets.
*
- * You most likely want to call gtk_list_view_set_model() to set
- * a model next.
- *
* The function takes ownership of the
* argument, so you can write code like
* ```
- * list_view = gtk_list_view_new_with_factory (
- * gtk_builder_list_item_factory_newfrom_resource ("/resource.ui"));
+ * list_view = gtk_list_view_new_with_factory (create_model (),
+ * gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
* ```
*
* Returns: a new #GtkListView using the given @factory
**/
GtkWidget *
-gtk_list_view_new_with_factory (GtkListItemFactory *factory)
+gtk_list_view_new_with_factory (GListModel *model,
+ GtkListItemFactory *factory)
{
GtkWidget *result;
- g_return_val_if_fail (GTK_IS_LIST_ITEM_FACTORY (factory), NULL);
+ g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
+ g_return_val_if_fail (factory == NULL || GTK_IS_LIST_ITEM_FACTORY (factory), NULL);
result = g_object_new (GTK_TYPE_LIST_VIEW,
+ "model", model,
"factory", factory,
NULL);
- g_object_unref (factory);
+ /* consume the references */
+ g_clear_object (&model);
+ g_clear_object (&factory);
return result;
}
GType gtk_list_view_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
-GtkWidget * gtk_list_view_new (void);
+GtkWidget * gtk_list_view_new (GListModel *model);
GDK_AVAILABLE_IN_ALL
-GtkWidget * gtk_list_view_new_with_factory (GtkListItemFactory *factory);
+GtkWidget * gtk_list_view_new_with_factory (GListModel *model,
+ GtkListItemFactory *factory);
GDK_AVAILABLE_IN_ALL
GListModel * gtk_list_view_get_model (GtkListView *self);
g_object_unref (filter);
list = gtk_list_view_new_with_factory (
+ g_object_ref (gtk_column_view_get_columns (GTK_COLUMN_VIEW (view))),
gtk_builder_list_item_factory_new_from_bytes (scope, g_bytes_new_static (factory_ui, strlen (factory_ui))));
- gtk_list_view_set_model (GTK_LIST_VIEW (list), gtk_column_view_get_columns (GTK_COLUMN_VIEW (view)));
gtk_box_append (GTK_BOX (hbox), list);
g_object_unref (scope);
while (g_list_model_get_n_items (toplevels))
g_main_context_iteration (NULL, TRUE);
-
return 0;
}
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);
gtk_stack_add_titled (GTK_STACK (stack), sw, "list", "GtkListView");
- list = gtk_list_view_new ();
+ list = gtk_list_view_new (create_model (0, 400, 1, FALSE));
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
- model = create_model (0, 400, 1, FALSE);
- gtk_list_view_set_model (GTK_LIST_VIEW (list), model);
- g_object_unref (model);
-
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_item), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_item), NULL);
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);
gtk_stack_add_titled (GTK_STACK (stack), sw, "tree", "Tree");
- list = gtk_list_view_new ();
+ list = gtk_list_view_new (create_tree_model (20, 20));
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
- model = create_tree_model (20, 20);
- gtk_list_view_set_model (GTK_LIST_VIEW (list), model);
- g_object_unref (model);
-
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_tree_item), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_tree_item), NULL);
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_list_item), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_list_item), NULL);
- listview = gtk_list_view_new_with_factory (factory);
+ listview = gtk_list_view_new_with_factory (NULL, factory);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_widget), NULL);
- listview = gtk_list_view_new_with_factory (factory);
+ listview = gtk_list_view_new_with_factory (NULL, factory);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
if (argc > 1)